package com.ecric.http.OkHttp3.package3;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * 参数
 * <h3>Description</h3>
 * TODO
 * <h3>Author</h3> luzhenbang
 * <h3>Date</h3> 04/04/2018 15:52
 * <h3>Copyright</h3> Copyright (c)2018 Shenzhen TL  Co., Ltd. Inc. All rights reserved.
 */
public class PostFormBuilder {

    private String url;
    private Object tag;
    private String json;
    /** 头部*/
    private Map<String, String> headers;
    /** 参数*/
    private Map<String, String> params;
    private List<FileInput> files;

    public PostFormBuilder(){

    }


    public PostFormBuilder url(String url){
        this.url = url;
        return this;
    }


    public PostFormBuilder tag(Object tag){
        this.tag = tag;
        return  this;
    }


    public PostFormBuilder headers(Map<String, String> headers){
        this.headers = headers;
        return  this;
    }

    public PostFormBuilder addHeader(String key,String value){
        if (null == headers){
            headers = new HashMap<>();
        }
        headers.put(key,value);
        return  this;
    }


    public PostFormBuilder addParams(Map<String, String> params){
        this.params = params;
        return  this;
    }

    public PostFormBuilder addParam(String key,String value){
        if (null == params){
            params = new HashMap<>();
        }
        params.put(key,value);
        return  this;
    }


    public PostFormBuilder addFiles(ArrayList<FileInput> files){
        this.files = files;
        return this;
    }

    public PostFormBuilder addFile(String name , String fileName ,File file){
        if (null == files){
            files  = new ArrayList<>();
        }
        files.add(new FileInput(name,fileName,file));
        return this;
    }

    public PostFormBuilder addFile(FileInput file){
        if (null == files){
            files  = new ArrayList<>();
        }
        files.add(file);
        return this;
    }


    public PostFormBuilder addJson(String json){
        this.json = json;
        return this;
    }


    public RequestCall build(){
        return new PostRequestBuilder(url,tag,json,headers,params,files).build();
    }

}
